package com.andnnl.reduce;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chenss on 2020/12/9.
 */
public class ReduceListTest {
    public static void main(String[] args) {
        List<Baz> list = new ArrayList<>();
        for (int i = 0; i < 200; i++) {
            list.add(new Baz("str" + i % 3, i));
        }
        Map<String, Baz> map = list.stream().collect(HashMap::new, (m, v) -> m.put(v.getType(), v.getTypeValue() == null ? null : v), HashMap::putAll);
        System.out.println(map);

        Map<String, Baz> map2 = list.stream()
//                .parallel()//并行
                .reduce(new HashMap<>(), (m, v) -> {
                    m.put(v.getType(), v);
                    return m;
                }, (x, y) -> {
                    x.putAll(y);
                    return x;
                });
        System.out.println(map2);
    }
}
